﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using App.Core.Extensions;
using App.Data;

public partial class Pages_Admin_JointVentureDetails : BasePage
{
    protected int _ID;

    protected void Page_Load(object sender, EventArgs e)
    {
        BindPageInfo();
        if (!IsPostBack)
        {
            BindJointVentureDetails();
        }
    }
    protected void BindPageInfo()
    {
        _ID = WebUtil.GetQueryStringInInt(AppConstants.QueryString.ID);
        Page.Title = WebUtil.GetPageTitle("Joint Venture Details.");
    }
    protected void BindJointVentureDetails()
    {
        BtcHousingEntities context = new BtcHousingEntities();
        var venture = context.JointVentures.FirstOrDefault(P => P.ID == _ID);
        if (venture == null)
            ShowNotFoundMessage();
        else
        {
            if (venture.VentureType == 1) //Land Owner
            {
                lblVentureType.Text = "Land Owner";
                divLandOwner.Visible = true;
                BindLandOwnerDetails(venture);
            }
            else //Developer
            {
                lblVentureType.Text = "Developer";
                divDeveloper.Visible = true;
                BindDeveloperDetails(venture);
            }
        }
    }
    protected void BindLandOwnerDetails(JointVenture venture)
    {
        lblLName.Text = venture.CustomerName.HtmlEncode();
        lblLAddress.Text = WebUtil.FormatText(venture.Address);
        lblLPhone.Text = venture.Phone.Trim().IsNullOrEmpty() ? "NA" : venture.Phone.HtmlEncode();
        lblLFax.Text = venture.Fax.Trim().IsNullOrEmpty() ? "NA" : venture.Fax.HtmlEncode();
        lblLEmail.Text = venture.Email.HtmlEncode();
        lblLPreferredCity.Text = venture.City.Name.HtmlEncode();
        lblLPreferredLocation.Text = venture.PreferredLocation.HtmlEncode();
        lblLLandSize.Text = venture.LandSize.HtmlEncode();
        lblLPropertyDescription.Text = venture.PropertyDescription.Trim().IsNullOrEmpty() ? "NA" : WebUtil.FormatText(venture.PropertyDescription);
        lblLRatioLandOwner.Text = venture.PreferredRatioOwner.ToString();
        lblLReatioDeveloper.Text = venture.PreferredRatioDeveloper.ToString();
    }
    protected void BindDeveloperDetails(JointVenture venture)
    {
        lblCustomerName.Text = venture.CustomerName.HtmlEncode();
        lblAddress.Text = WebUtil.FormatText(venture.Address);
        lblPhone.Text = venture.Phone.Trim().IsNullOrEmpty() ? "NA" : venture.Phone.HtmlEncode();
        lblFax.Text = venture.Fax.Trim().IsNullOrEmpty() ? "NA" : venture.Fax.HtmlEncode();
        lblEmail.Text = venture.Email.HtmlEncode();
        lblPreferredCity.Text = venture.City.Name.HtmlEncode();
        lblPreferredArea.Text = venture.PreferredLocation.HtmlEncode();
        lblLandSize.Text = venture.LandSize.HtmlEncode();
        lblPropertyDescription.Text = venture.PropertyDescription.Trim().IsNullOrEmpty() ? "NA" : WebUtil.FormatText(venture.PropertyDescription);
        lblRatioLandOwner.Text = venture.PreferredRatioOwner.ToString();
        lblRatioDeveloper.Text = venture.PreferredRatioDeveloper.ToString();
    }
    protected void ShowNotFoundMessage()
    {
        WebUtil.ShowMessageBox(divMessage, "Requested Joint Venture was not found.", true);
        pnlFormContainer.Visible = false;
    }
}